namespace SimpleWebServices.Configuration
{
    using System.Configuration;
    using System.Xml;
    using Xunit;

    public sealed class AnalyticsConfigurationFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<AnalyticsConfiguration>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IConfigurationSectionHandler>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new AnalyticsConfiguration());
        }

        [Fact]
        public void op_Settings()
        {
            Assert.Null(AnalyticsConfiguration.Settings());
        }

        [Fact]
        public void op_Settings_string()
        {
            Assert.Null(AnalyticsConfiguration.Settings("simplewebservices/analytics"));
        }

        [Fact]
        public void op_Create_object_object_XmlNodeNull()
        {
            AnalyticsSettings actual = new AnalyticsConfiguration().Create(null, null, null as XmlNode) as AnalyticsSettings;

            Assert.Null(actual);
        }

        [Fact]
        public void op_Create_object_object_XmlNodeEmpty()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<analytics />");

            AnalyticsSettings actual = new AnalyticsConfiguration().Create(null, null, xml.DocumentElement) as AnalyticsSettings;

            Assert.False(actual.Enabled);
        }

        [Fact]
        public void op_Create_object_object_XmlNode()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<analytics enabled='true' />");

            AnalyticsSettings actual = new AnalyticsConfiguration().Create(null, null, xml.DocumentElement) as AnalyticsSettings;

            Assert.True(actual.Enabled);
        }

        [Fact]
        public void op_Create_object_object_XmlNodeInvalid()
        {
            XmlDocument xml = new XmlDocument();
            xml.LoadXml("<bad-name/>");

            Assert.Throws<ConfigurationErrorsException>(() => new AnalyticsConfiguration().Create(null, null, xml.DocumentElement));
        }
    }
}